using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Preferences;
using Android.Runtime;
using Android.Telephony;
using Android.Util;
using Android.Views;
using Android.Widget;

namespace NorthStar.Driver
{
    public class FakeGps
    {
       public double lat{get;set;}
		public double lng{get;set;}
    }
    public class Helper
    {
        public static FakeGps GetFakeGps(Context context)
        {
            List<FakeGps> fakeGpsList = new List<FakeGps>
                                            {
                                                new FakeGps {lat = -35.27946, lng = 149.128748},
                                                new FakeGps {lat = -35.275256, lng = 149.129735},
                                                new FakeGps {lat = -35.268283, lng = 149.130637},
                                                new FakeGps {lat = -35.26061, lng = 149.132182},
                                                new FakeGps {lat = -35.258857, lng = 149.115616},
                                                new FakeGps {lat = -35.242737, lng = 149.109393},
                                                new FakeGps {lat = -35.23492, lng = 149.092442},
                                                new FakeGps {lat = -35.242176, lng = 149.089524},
                                                new FakeGps {lat = -35.253251, lng = 149.074375},
                                                new FakeGps {lat = -35.256124, lng = 149.067294},
                                                new FakeGps {lat = -35.249115, lng = 149.06193},
                                                new FakeGps {lat = -35.303455, lng = 149.125401},
                                                new FakeGps {lat = -35.309409, lng = 149.118878},
                                                new FakeGps {lat = -35.312211, lng = 149.106089},
                                                new FakeGps {lat = -35.315922, lng = 149.091669}
                                            };

            FakeGps gps = new FakeGps { lat = -35.27946, lng = 149.128748 }; //setup canberra default

            ISharedPreferences _preferences = PreferenceManager.GetDefaultSharedPreferences(context);
            var lastIndex = _preferences.GetInt("index", 0);
            if (lastIndex >= fakeGpsList.Count)
                lastIndex = 0;

            gps = fakeGpsList[lastIndex];
            lastIndex++;

            ISharedPreferencesEditor editor = _preferences.Edit();
            editor.PutInt("index", lastIndex);
            editor.Commit();
            return gps;
        }
        public static string GetServer(Context context)
        {
            ISharedPreferences _preferences = PreferenceManager.GetDefaultSharedPreferences(context);

            return _preferences.GetString("server", "http://192.168.1.1/TheNorthStar");
        }
        public static string GetDeviceId(Context context)
        {
            ISharedPreferences _preferences = PreferenceManager.GetDefaultSharedPreferences(context);

           
            string imei = _preferences.GetString("imei", "ABC12345");
            return imei;
            /*TelephonyManager telephonyMgr = context.GetSystemService(Context.TelephonyService) as TelephonyManager;

            string deviceId = telephonyMgr.DeviceId == null ? imei : telephonyMgr.DeviceId;

            return deviceId;*/
        
        }



        /// <summary>
        /// Retrieve the PhoneNumber from the TelephonyManager
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string GetPhoneNumber(Context context)
        {
            ISharedPreferences _preferences = PreferenceManager.GetDefaultSharedPreferences(context);

            string phoneNumberTemp = _preferences.GetString("phoneNumber", "04112345678");
            return phoneNumberTemp;
            /*TelephonyManager telephonyMgr = context.GetSystemService(Context.TelephonyService) as TelephonyManager;
            string phoneNumber = telephonyMgr.Line1Number == null ? phoneNumberTemp : telephonyMgr.Line1Number;

            return phoneNumber;*/

        }
    }
}